package services

import (
	"context"
	"sanrenx.com/xyxf/pkg/gredis"
)

/**
 * @Description: 更新缓存列表中 HOT 热度分值
 * @param cacheKey
 * @param id ID
 * @param hot HOT
 */
func RefreshCacheKeyHot(cacheKey string, id uint64, hot int) {
	ctx := context.Background()
	if count, err := gredis.ZCard(ctx, cacheKey); err == nil && count > 0 {
		keys, _ := gredis.ZRange(ctx, cacheKey, 0, count)
		for _, key := range keys {
			if _, err := gredis.ZScore(ctx, key, id); err == nil {
				_ = gredis.ZAdd(ctx, key, id, float64(hot))
			}
		}
	}
}
